package ODtest.tongjirul;

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        SortedMap<String,Integer> count = Collections.synchronizedSortedMap(
            new TreeMap<String,Integer>(
                new Comparator(){
                    @Override
                    public int compare(Object o1, Object o2) {
                        return (((Map.Entry<String, Integer>) o2).getValue()).compareTo(((Map.Entry<String, Integer>) o1).getValue());
                    }
                }));
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String url = in.nextLine();
            if (url.contains(".com")) { // url
                if (count.containsKey(url)) {
                    count.put(url, count.get(url) + 1);
                } else {
                    count.put(url, 1);
                }
            } else { // 数字， 输出topN
                count.entrySet().parallelStream().sorted().limit(Integer.getInteger(url)).forEach(e-> {
                    System.out.println(e.getKey());
                    System.out.println(",");
                });
            }
        }
    }
}